package test4;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTopic;

public class TestPubProducer {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://10.222.29.178:61616");
		Destination topic = new ActiveMQTopic("topic1");
		Connection connection = factory.createConnection();
		connection.start();
		
		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
		MessageProducer producer = session.createProducer(topic);
		
		TextMessage msg1 = session.createTextMessage("Hello1!");
		producer.send(msg1);
//		int m=1/0;
		TextMessage msg2 = session.createTextMessage("Hello2!");
		producer.send(msg2);
		session.commit();
		
		producer.close();
		session.close();
		connection.close();
	}

}
